package com.springboot.cloud.demos.ribbon.rest;

import com.springboot.cloud.common.core.entity.vo.Result;
import com.springboot.cloud.demos.entity.form.UnitForm;
import com.springboot.cloud.demos.ribbon.service.UnitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
public class UnitController {

    @Autowired
    private UnitService unitService;

    @GetMapping("/unit")
    public Result<List<Map<String, Object>>> query(@RequestParam("levelId") String levelId) {
        return unitService.query(levelId);
    }

    @GetMapping("/queryByLevelAndUser")
    public Result<List<Map<String, Object>>> queryByLevelAndUser(@RequestParam("levelId") String levelId, @RequestParam("userId") String userId) {
        return unitService.queryByLevelAndUser(levelId, userId);
    }

    @GetMapping("/unit/{id}")
    public Result get(@PathVariable(value = "id") String id) {
        return unitService.get(id);
    }

    @PostMapping("/unit")
    public Result add(@RequestBody UnitForm unitForm) {
        return unitService.save(unitForm);
    }

    @PutMapping(value = "/unit")
    public Result update(@RequestBody UnitForm unitForm) {
        return unitService.update(unitForm);
    }
}
